/**
 * 
 */
package com.yidu.menuProject.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.menuProject.action.vo.EhyManagerVo;
import com.yidu.menuProject.common.Pages;
import com.yidu.menuProject.common.ResultMap;
import com.yidu.menuProject.common.Tool;
import com.yidu.menuProject.model.EhyManagerModel;
import com.yidu.menuProject.model.EhyManagerRoleModel;
import com.yidu.menuProject.model.EhyModuleModel;
import com.yidu.menuProject.model.EhyRoleModel;
import com.yidu.menuProject.service.ManagerService;

/**
 * @author zoutian
 * date2018年7月20日
 * 
 */
@Controller
@RequestMapping("/ManagerAction")
public class ManagerAction {
	@Resource
	private ManagerService service;
	/**  
	 * 餐馆人员管理权限
	 * @param manUser 名称
	 * @return 集合
	 */
	@RequestMapping("/findManaModule")
	@ResponseBody
	public List<EhyModuleModel> findManaModule(HttpServletRequest request) {
		EhyManagerVo mana=(EhyManagerVo)request.getSession().getAttribute("mana");
		List<EhyModuleModel> list=service.findManaModule(mana.getManId());
		System.out.println(list.toString());
		return list;
	}
	
	@RequestMapping("/findAll")
	@ResponseBody
	public ResultMap<List<EhyManagerModel>> findAll(Pages page,@RequestParam("limit") int limit,HttpServletRequest request){
	    System.out.println("backContent========================"+limit);
	    page.setRows(limit);
	   
	    EhyManagerVo mana=(EhyManagerVo)request.getSession().getAttribute("mana");
	    if(!Tool.isEmpty(mana.getMealId())){
	    	 page.setMealId(mana.getMealId());
	    }
	   
	    System.out.println("page:"+page.toString());
	    List<EhyManagerModel> contentList=service.findAll(page);
	    int totals=service.findByCount(page);
	    page.setTotalRecord(totals);
	    return new ResultMap<List<EhyManagerModel>>("",contentList,0,totals);
	}
	/**
	 * 查询所有角色
	 * @return 集合
	 */
	@RequestMapping("/findRole")
	@ResponseBody
	public List<EhyRoleModel> findRole() {
		List<EhyRoleModel> list=service.findRole();
		System.out.println(list.toString());
		return list;
	}
	/**
	 * 增加用户角色
	 * @param mana
	 * @param manaRole
	 * @return
	 */
	@RequestMapping("/addManaRole")
	public String addManaRole(HttpServletRequest request ,EhyManagerModel mana,EhyManagerRoleModel manaRole){
		EhyManagerVo man=(EhyManagerVo)request.getSession().getAttribute("mana");
		mana.setMealId(man.getMealId());
		int rows=service.addManaRole(mana, manaRole);
		return "redirect:../pages/html/manager.html";
	}
	/**
	 * 管理者修改上屏的方法
	 * @param manId 管理者ID
	 * @return 字符串
	 */
	@RequestMapping("/showManaUpdate")
	@ResponseBody
	public List<EhyManagerModel> showManaUpdate(String manId){
		List<EhyManagerModel> list=service.showManaUpdate(manId);
		return list;
	}
	/**
	 * 修改管理者角色
	 * @param mana
	 * @param manaRole
	 * @return
	 */
	@RequestMapping("/updateManaRole")
	public String updateManaRole(EhyManagerModel mana,EhyManagerRoleModel manaRole) {
		int rows=service.updateManaRole(mana, manaRole);
		return "redirect:../pages/html/manager.html";
	}
	/**
	 * 删除管理者
	 * @param mana
	 * @return 字符串
	 */
	@RequestMapping("/deleteMana")
	@ResponseBody
	public String deleteMana(EhyManagerModel mana) {
		int rows=service.deleteMana(mana);
		return "ok";
	}
}
